/*
* @Author: Administrator
* @Date:   2018-02-05 08:53:12
* @Last Modified by:   Administrator
* @Last Modified time: 2018-02-05 15:46:49
*/
import React from 'react'
// import PropTypes from 'prop-types'

class Bundle extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      mod: null,
    }
  }
  componentWillMount() {
    this.load(this.props)
  }
  componentWillReceiveProps(nextProps) {
    if (this.props !== nextProps) {
      this.load(nextProps)
    }
  }
  load(props) {
    this.setState({
      mod: null,
    })
    props.getComponent()
      .then((m) => {
        const Mod = m.default ? m.default : m;
        this.setState({ mod: Mod });
      })
  }
  render() {
    const Mod = this.state.mod
    return (
      Mod ? <Mod {...this.props} /> : null
    )
  }
}
Bundle.propTypes = {
  // path: PropTypes.string.require,
};

export default Bundle;
